<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:v-for="http://www.w3.org/1999/xhtml"
      xmlns:v-on="http://www.w3.org/1999/xhtml" lang="en">

<head>
    <meta charset="utf-8"/>
    <title>Java-ES</title>
    <link rel="stylesheet" th:href="@{/css/style.css}"/>
</head>

<body class="pg">
<div class="page" id="app">
    <div id="mallPage" class=" mallist tmall- page-not-market ">

        <!-- 头部搜索 -->
        <div id="header" class=" header-list-app">
            <div class="headerLayout">
                <div class="headerCon ">
                    <!-- Logo-->
                    <h1 id="mallLogo">
                        <img th:src="@{/images/jdlogo.png}" alt="">
                    </h1>

                    <div class="header-extra">

                        <!--搜索-->
                        <div id="mallSearch" class="mall-search">
                            <form name="searchTop" class="mallSearch-form clearfix">
                                <fieldset>
                                    <legend>搜索</legend>
                                    <div class="mallSearch-input clearfix">
                                        <div class="s-combobox" id="s-combobox-685">
                                            <div class="s-combobox-input-wrap">
                                                <input type="text" v-model="keyword" autocomplete="off" value="dd" id="mq"
                                                       class="s-combobox-input" aria-haspopup="true">
                                            </div>
                                        </div>
                                        <button type="submit" @click.prevent="searchkey" id="searchbtn">搜索</button>
                                    </div>
                                </fieldset>
                            </form>
                            <ul class="relKeyTop">

                                <li><a>ES</a></li>

                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 商品详情页面 -->
        <div id="content">
            <div class="main">
                <!-- 品牌分类 -->
                <form class="navAttrsForm">
                    <div class="attrs j_NavAttrs" style="display:block">
                        <div class="brandAttr j_nav_brand">
                            <div class="j_Brand attr">
                                <div class="attrKey">
                                    品牌
                                </div>
                                <div class="attrValues">
                                    <ul class="av-collapse row-2">
                                        <li><a href="#"> Java </a></li>
                                        <li><a href="#"> ES </a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>

                <!-- 排序规则 -->
                <div class="filter clearfix">
                    <a class="fSort fSort-cur">综合<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">人气<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">新品<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">销量<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">价格<i class="f-ico-triangle-mt"></i><i class="f-ico-triangle-mb"></i></a>
                </div>

                <!-- 商品详情 -->
                <div class="view grid-nosku">

                    <div class="product" v-for = "item in results" >
                        <div class="product-iWrap">
                            <!--商品封面-->
                            <div class="productImg-wrap">
                                <a class="productImg">
                                    <img :src="item.img">
                                </a>
                            </div>
                            <!--价格-->
                            <p class="productPrice">
                                <em> {{item.price}}</em>
                            </p>
                            <!--标题-->
                            <p class="productTitle" @click.prevent="queryDetail(item.id)">
                                <a v-html = "item.name"> </a>
                            </p>
                            <!-- 店铺名 -->
                            <div class="productShop">
                                <span>店铺： ES </span>
                                <span>相关度 <a>{{item.score}}</a></span>
                            </div>
                            <!-- 成交信息 -->
                            <p class="productStatus">
                                <span>月成交<em>999笔</em></span>
                                <span>评价 <a>3</a></span>
                            </p>
                        </div>
                    </div>
                </div>
                <div>
                    <el-pagination
                            background
                            @current-change="currentChange"
                            layout="prev, pager, next"
                            :total="1000">
                    </el-pagination>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="app2">
   <!-- <button type="submit" v-on:click="handleClick" >搜索</button>-->

</div>
  <!--前端使用vue-->
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.11"></script>
<script th:src="@{/js/axios.min.js}"></script>
<!--<script th:src="@{/js/vue.min.js}"></script>-->
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

<script>
    let vue = new Vue({
        el:"#app",
        data:{
            keyword:"",
            results:[]
        },
        methods:{
            searchkey(){
                var keyword = this.keyword;
                console.log(keyword);
                // 对接 接口
                axios.get("/queryGoods/"+ keyword + "/1/10").then(response => {
                    console.log(response);
                    this.results = response.data;
                })
            },
            currentChange(pageNo) {
                var keyword = this.keyword;
                console.log(keyword);

                axios.get("/queryGoods/"+ keyword + `/${pageNo}/10`).then(response => {
                    console.log(response);
                    this.results = response.data;
                })
            },
            queryDetail(id) {
                console.log(id);
                axios.get("/book/queryById/" + `${id}`).then(response => {
                    console.log(response);
                    this.results = response.data;
                })
            }

        }
    });

    let vue2 = new Vue({
        el:"#app2",
        methods:{
            handleClick(){
                let _this = this;
                console.log(this);


                    // 注册拍照按钮的单击事件
                    let video = this.$refs['vd'] ;
                    let canvas = this.$refs['cav'];
                    let form = this.$refs["myForm"];
                    let context = canvas.getContext('2d');
                    // 绘制画面
                    context.drawImage(video, 0, 0, 200, 200);
                    let base64Data = canvas.toDataURL('image/jpg');

                    // 封装blob对象
                    let blob = this.dataURItoBlob(base64Data, 'camera.jpg');
                    // base64 转图片file
                    let formData = new FormData() ;
                    formData.append('file', blob);

                    this.imgUrl = base64Data;
                    console.log(base64Data);
                    checkFace(formData).then(res => {
                        if (res.data.isSuc) {
                            axios({
                                method: 'post',
                                url: '/api/frame/facelogin/' + this.$route.query.code,
                                data: formData
                            }).then(function(response) {
                                console.log(response);
                                _this.states = true;
                                _this.canvasShow = false;
                                _this.tipShow = true;
                                _this.$message.success('验证通过' + '!')
                            }).catch(function(error) {
                                console.log(error)
                            })
                         } else {
                            return false
                        }
                    })

            },

            dataURItoBlob(base64Data) {
                var byteString;

                if (base64Data.split(',')[0].indexOf('base64') >= 0){
                    byteString = atob(base64Data.split(',')[1])
                } else {
                    byteString = unescape(base64Data.split(',')[1]);
                     var mimeString = base64Data.split(',')[0].split(':')[1].split(';')[0];
                      var ia = new Uint8Array(byteString.length);
                      for (var i = 0; i < byteString.length; i++) {
                          ia[i] = byteString.charCodeAt(i)
                      }
                    return new Blob([ia], { type: mimeString })
                }
            }

        }
    });

</script>

</body>
</html>